package cn.changsha.xczxapp.ffmpeg;

/**
 * Created by Liuhailong on 2018/7/5 15:51
 * e-mail:419977897@qq.com
 */

public class FFmpegUtils {

    public static String[]runCommand(int type, String filePath1, String filePath2, String vf, String s) {

        /*ret = FFmpegNativeBridge.runCommand(new String[]{
                "ffmpeg",
                "-i", filePath,
                "-y",
                "-c:v", "libx264",
                "-c:a", "aac",
                //"-vf", "scale=-2:640",//尺寸
                "-vf", vf,//尺寸
                "-s", s,
                "-preset", "ultrafast",
                "-b:v", "500k",//视频比特率  320k 450k
                //"-b:a", "64k",//96k 音频比特率
                //"-r", "15",//帧率
                "-ar", "22050",//音频采样率
                "-map", "0",//mp4索引
                "-movflags", "faststart",
                compressFilePath});*/

        String[]runCommand = null;
        switch (type) {
            case 0:
                runCommand = new String[]{
                        "ffmpeg",
                        "-i", filePath1,
                        "-y",
                        "-c:v", "libx264",
                        "-c:a", "aac",
                        //"-vf", "scale=-2:640",//尺寸
                        "-vf", vf,//尺寸
                        "-s", s,
                        //"-preset", "ultrafast",
                        "-b:v", "750k",//视频比特率  320k 450k
                        "-b:a", "64k",//96k 音频比特率
                        "-r", "15",//帧率
                        "-ar", "22050",//音频采样率
                        //"-map", "0",//mp4索引
                        "-movflags", "faststart",
                        filePath2};

                break;
            case 1:
                runCommand = new String[]{
                        "ffmpeg",
                        "-i", filePath1,
                        "-y",
                        "-c:v", "libx264",
                        "-c:a", "aac",
                        //"-vf", "scale=-2:640",//尺寸
                        "-vf", vf,//尺寸
                        "-s", s,
                        //"-preset", "ultrafast",
                        "-b:v", "750k",//视频比特率  320k 450k
                        //"-b:a", "64k",//96k 音频比特率
                        "-r", "15",//帧率
                        "-ar", "22050",//音频采样率
                        //"-map", "0",//mp4索引
                        "-movflags", "faststart",
                        filePath2};
                break;
            case 2:
                runCommand = new String[]{
                        "ffmpeg",
                        "-i", filePath1,
                        "-y",
                        "-c:v", "libx264",
                        "-c:a", "aac",
                        //"-vf", "scale=-2:640",//尺寸
                        "-vf", vf,//尺寸
                        //"-preset", "ultrafast",
                        "-b:v", "750k",//视频比特率  320k 450k
                        "-b:a", "64k",//96k 音频比特率
                        "-r", "15",//帧率
                        "-ar", "22050",//音频采样率
                        //"-map", "0",//mp4索引
                        "-movflags", "faststart",
                        filePath2};
                break;
            case 3:
                runCommand = new String[]{
                        "ffmpeg",
                        "-i", filePath1,
                        "-y",
                        "-c:v", "libx264",
                        "-c:a", "aac",
                        //"-vf", "scale=-2:640",//尺寸
                        "-s", s,
                        //"-preset", "ultrafast",
                        "-b:v", "750k",//视频比特率  320k 450k
                        "-b:a", "64k",//96k 音频比特率
                        "-r", "15",//帧率
                        "-ar", "22050",//音频采样率
                        //"-map", "0",//mp4索引
                        "-movflags", "faststart",
                        filePath2};
                break;
        }
        return runCommand;
    }


    public static int checkSizeValue(int iValue) {
        int[] iSizeAry = new int[]{180, 240, 270, 320, 360, 406, 480, 540, 640, 720, 854, 960, 1080, 1280, 1920};
        int iSizeSpan = 100, iSizeIndex = -1;
        for (int i = 0; i < iSizeAry.length; i++) {
            int iSizeSpanTemp = Math.abs(iValue - iSizeAry[i]);
            if (iSizeSpanTemp < iSizeSpan) {
                iSizeIndex = i;
                iSizeSpan = iSizeSpanTemp;
            }
        }
        if (iSizeIndex > -1){
            iValue = iSizeAry[iSizeIndex];
        }
        return iValue;
    }
}
